package A_review.review9_13;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Class46 {

    //TODO:2023/9/13  全排列


    
    
    List<List<Integer>>  result;
    LinkedList<Integer> path;
    boolean[]  record;
    public List<List<Integer>> permute(int[] nums) {
        result=new ArrayList<>();
        path=new LinkedList<>();
        record= new boolean[nums.length];
        backTracking(nums);
        

        return  result;

    }
    public  void  backTracking(int[] nums){
        if (path.size()== nums.length){
            result.add(new ArrayList<>(path));
            //TODO:2023/9/13  加不加return 对结果没有影响   那么什么时候必须要加上return呢
//            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (record[i]){
                continue;
            }
            path.add(nums[i]);
            record[i]=true;
            backTracking(nums);
            path.removeLast();
            record[i]=false;
            
        }
    }

    public static void main(String[] args) {

        Class46 class46 = new Class46();
        int[] arr={1,2,3};
        List<List<Integer>> permute = class46.permute(arr);
        System.out.println(permute.toString());
    }
    
    
    
    
}
